﻿using System;

namespace Link_eLab.Helper
{
    /// <summary>
    /// Guid工具类
    /// </summary>
    public static class GuidHelper
    {
        /// <summary>
        /// 获取一个大写的字符串
        /// </summary>
        /// <param name="str"></param>
        /// <returns>JSON结果集</returns>
        private static string upper(string str)
        {
            return str.ToUpper();
        }

        /// <summary>
        /// 获取32位不包含“-”号的GUID字符串
        /// </summary>
        /// <returns>JSON结果集</returns>
        public static string NewGuidFormatN(bool isUpper = false)
        {
            var guid = Guid.NewGuid().ToString("N");
            guid += DateTime.Now.Ticks.ToString().Substring(1, 8);
            return isUpper == true ? upper(guid) : guid;
        }

        /// <summary>
        /// 获取32位包含“-”号的GUID字符串
        /// </summary>
        /// <param name="isUpper"></param>
        /// <returns>JSON结果集</returns>
        public static string NewGuidFormatD(bool isUpper = false)
        {
            var guid = Guid.NewGuid().ToString("D");
            return isUpper == true ? upper(guid) : guid;
        }

        /// <summary>
        /// 获取32位包含“-”号的GUID被“(”、“)”包括的字符串
        /// </summary>
        /// <param name="isUpper"></param>
        /// <returns>JSON结果集</returns>
        public static string NewGuidFormatP(bool isUpper = false)
        {
            var guid = Guid.NewGuid().ToString("P");
            return isUpper == true ? upper(guid) : guid;
        }

        /// <summary>
        /// 获取32位包含“-”号的GUID被“{”、“}”包括的字符串
        /// </summary>
        /// <param name="isUpper"></param>
        /// <returns>JSON结果集</returns>
        public static string NewGuidFormatB(bool isUpper = false)
        {
            var guid = Guid.NewGuid().ToString("B");
            return isUpper == true ? upper(guid) : guid;
        }

        /// <summary>
        /// 获取4个被“{”、“}”包括的十六进制数，其中第四个值位8个被“{”、“}”包括的十六进制数字符串
        /// </summary>
        /// <param name="isUpper"></param>
        /// <returns>JSON结果集</returns>
        public static string NewGuidFormatX(bool isUpper = false)
        {
            var guid = Guid.NewGuid().ToString("X");
            return isUpper == true ? upper(guid) : guid;
        }
    }
}
